home *** CD-ROM | disk | FTP | other *** search
/ MacAddict 116 / MacAddict 116 (Mac Power Pack)(theDISC)(April 2006).iso / Software / Interface / HolidayWidgetBundle.dmg / / FTP Drop.wdgt / ftpdrop.js < prev    next >
Encoding:
JavaScript  |  2005-06-24  |  21.4 KB  |  773 lines

  1. //this widget is a nice example of the joys and problems of wrapping a commandline tool...
  2. var file, nickname, username, password, init_path, address, server;
  3.  
  4. function upload() {
  5.     if (FTPDrop) {
  6.         if (init_path.charAt(0) != "/") init_path = "/" + init_path;
  7.         if (init_path.charAt(init_path.length-1) != "/") init_path += "/";
  8.         
  9.         //alert(init_path);
  10.         
  11.         var new_address = "ftp://" + address + init_path;
  12.         alert(new_address);
  13.         FTPDrop.uploadFile(file, new_address, username, password);
  14.     }
  15. }
  16.  
  17. function showProgress(progress) {
  18.     progress = progress.substring(progress.lastIndexOf(" ")+1, progress.length);
  19.     if (progress != "") document.getElementById("up_percentage").innerText = progress + "%";
  20.     //the above happens sometimes...
  21. }
  22.  
  23. //three functions used depending on curls exit status:
  24. function noHost() {
  25.     drop_zone.style.backgroundImage = "url(images/connection_failed.png)";
  26.     setTimeout(
  27.         function() {
  28.             toggleSettings();
  29.             resetForSendingAgain();
  30.         }, 1000);
  31. }
  32.  
  33. function authFailed() {
  34.     drop_zone.style.backgroundImage = "url(images/authentication_failed.png)";
  35.     setTimeout(
  36.         function() {
  37.             toggleSettings();
  38.             resetForSendingAgain();
  39.         }, 1000);
  40. }
  41.  
  42. function successfullUpload() {
  43.     drop_zone.style.backgroundImage = "url(images/complete.png)";
  44.     setTimeout(
  45.         function() {
  46.             resetForSendingAgain();
  47.         }, 1000);
  48. }
  49.  
  50. function resetForSendingAgain() {
  51.     document.getElementById("info_display").innerText = "ftp to";
  52.     document.getElementById("up_percentage").style.visibility = "hidden";
  53.     document.getElementById("nickname_display").innerText = nickname;
  54.     document.getElementById("up_percentage").innerText = "0%";
  55.     
  56.     drop_zone.style.backgroundImage = "url(images/dropHere.png)";
  57.     
  58.     drop_zone.addEventListener("drop", getFile, true);
  59.     drop_zone.addEventListener("dragenter", doDragEnter, true);
  60.     drop_zone.addEventListener("dragover", doDragMove, true);
  61.     drop_zone.addEventListener("dragleave", doDragLeave, true);
  62.     
  63. }
  64.  
  65. function getFile(e) {
  66.     file = getUnixFilePath(e.dataTransfer.getData("text/uri-list"));
  67.     //alert(file);
  68.     document.getElementById("info_display").innerText = "progress";
  69.     document.getElementById("up_percentage").style.visibility = "visible";
  70.     document.getElementById("nickname_display").innerText = getFileName(file);
  71.     
  72.     var drop_zone = document.getElementById("drop_zone");
  73.     
  74.     drop_zone.style.backgroundImage = "url(images/transferring.png)";
  75.     
  76.     
  77.     drop_zone.removeEventListener("drop", getFile, true);
  78.     drop_zone.removeEventListener("dragenter", doDragEnter, true);
  79.     drop_zone.removeEventListener("dragover", doDragMove, true);
  80.     drop_zone.removeEventListener("dragleave", doDragLeave, true);
  81.     
  82.     setTimeout("upload()", 0);
  83.     
  84.     e.preventDefault();
  85.     e.stopPropagation();
  86. }
  87.  
  88. function getUnixFilePath(file) {
  89.     if (file.indexOf("file://localhost") != -1) file = file.substring(new String("file://localhost").length, file.length);
  90.  
  91.     //file = file.replace(/%20/g,"\\ ");
  92.     file = file.replace(/%20/g," "); //plugin doesn't use escaped paths
  93.     file = decodeURI(file);
  94.     return file;
  95. }
  96.  
  97. function getFileName(file) {
  98.     var tmp = file.split("/");
  99.     
  100.     tmp = tmp[tmp.length-1];
  101.     tmp = tmp.replace(/\\ /g, " ");
  102.  
  103.     return tmp;
  104. }
  105.  
  106. //three functions needed to stop event propogation so we can capture the ondrop event
  107. //for the element we want.
  108. function doDragEnter (e) {
  109.     e.target.style.backgroundImage = "url(images/dropHere_over.png)";
  110.     e.preventDefault();
  111.     e.stopPropagation();
  112. }
  113.  
  114. function doDragLeave (e) {
  115.     document.getElementById("drop_zone").style.backgroundImage = "url(images/dropHere.png)";
  116.     e.preventDefault();
  117.     e.stopPropagation();
  118. }
  119.  
  120. function doDragMove (e) {
  121.     e.preventDefault();
  122.     e.stopPropagation();
  123. }
  124.  
  125. function getSavedServers() {
  126.     var servers_request = new XMLHttpRequest();
  127.     servers_request.open("GET", "servers.xml", false);
  128.     servers_request.send(null);
  129.  
  130.     return servers_request.responseXML;
  131. }
  132.  
  133. function checkForSavedServer(name) {
  134.     var data = getSavedServers();
  135.     var servers = data.getElementsByTagName("server");
  136.     
  137.     for (var i=0; i < servers.length; i++)
  138.         if (servers[i].getAttribute("nickname") == name) return true;
  139.     
  140.     return false;
  141. }
  142.  
  143. function getSavedServerInfo(name) {
  144.     var data = getSavedServers();
  145.     var servers = data.getElementsByTagName("server");
  146.     
  147.     for (var i=0; i < servers.length; i++) {
  148.         if (servers[i].getAttribute("nickname") == name) {
  149.             nickname = servers[i].getAttribute("nickname");
  150.             address = servers[i].getAttribute("address");
  151.             username = servers[i].getAttribute("username");
  152.             init_path = servers[i].getAttribute("path");
  153.             
  154.             //alert(nickname + ", " + address + ", " + username + ", " + init_path);
  155.             
  156.             document.getElementById("nickname").value = nickname;
  157.              document.getElementById("username").value = username;
  158.              document.getElementById("address").value = address;
  159.              document.getElementById("path").value = init_path;
  160.             
  161.             document.getElementById("nickname_display").innerText = nickname;
  162.             
  163.             document.getElementById("password").focus();
  164.             
  165.             break;
  166.         }
  167.     }
  168. }
  169.  
  170. function saveServer() {
  171.     var data = getSavedServers();
  172.     var servers = data.getElementsByTagName("server");
  173.     var servers_length =  data.getElementsByTagName("server").length;
  174.     
  175.     /*
  176.         Have a new DOM document that we put all the info into, rather than manipulating var data.
  177.         If we find it belwow, put it in (clone the node) then 
  178.         make the new ones for the devices we don't have.
  179.      */
  180.  
  181.     var xml_doc = document.implementation.createDocument('', '', null);
  182.     var servers_node = xml_doc.createElement("servers");
  183.         
  184.     for (var i=0; i < servers_length; i++) {
  185.         if (servers[i].getAttribute("nickname") != nickname) {
  186.             var s = xml_doc.createElement("server");
  187.             s.setAttribute("nickname", servers[i].getAttribute("nickname"));
  188.             s.setAttribute("address", servers[i].getAttribute("address"));
  189.             s.setAttribute("username", servers[i].getAttribute("username"));
  190.             s.setAttribute("path", servers[i].getAttribute("path"));
  191.             
  192.             servers_node.appendChild(s);
  193.         }
  194.     }
  195.     
  196.     //and now put in the server they've just added:
  197.     var s = xml_doc.createElement("server");
  198.     s.setAttribute("nickname", nickname);
  199.     s.setAttribute("address", address);
  200.     s.setAttribute("username", username);
  201.     s.setAttribute("path", init_path);
  202.     
  203.     servers_node.appendChild(s);
  204.     
  205.     xml_doc.appendChild(servers_node);
  206.     
  207.     //alert('done');
  208.     
  209.     //and write the XML doc to our cache file:                
  210.     var xml_source = '<?xml version="1.0" encoding="UTF-8"?>\n';
  211.     xml_source += new XMLSerializer().serializeToString(xml_doc);
  212.     
  213.     //alert('xml source: ' + xml_source);
  214.     
  215.     widget.system("/bin/rm servers.xml", null);
  216.     widget.system("/bin/echo '" + xml_source + "' > servers.xml", null);
  217.     
  218.     //alert('file written');
  219. }
  220.  
  221. function verifySettings() {
  222.     nickname = document.getElementById("nickname"); //.value;
  223.     username = document.getElementById("username"); //.value;
  224.     password = document.getElementById("password"); //.value;
  225.     address = document.getElementById("address"); //.value;
  226.     init_path = document.getElementById("path"); //.value;
  227.     
  228.     var arrow = document.getElementById("arrow");
  229.     
  230.     
  231.     nickname.style.background = "white";
  232.     username.style.background = "white";
  233.     password.style.background = "white";
  234.     address.style.background = "white";
  235.     
  236.     if (nickname.value == "") {
  237.         arrow.style.top = "43px";
  238.         arrow.style.display = "block";
  239.         nickname.style.background = "indianred";
  240.         nickname.focus();
  241.         return false;
  242.     }
  243.     
  244.     if (address.value == "") {
  245.         arrow.style.top = "82px";
  246.         arrow.style.display = "block";
  247.         address.style.background = "indianred";
  248.         address.focus();
  249.         return false;
  250.     }
  251.     
  252.     if (username.value == "") {
  253.         arrow.style.top = "122px";
  254.         arrow.style.display = "block";
  255.         username.style.background = "indianred";
  256.         username.focus();
  257.         return false;
  258.     }
  259.     
  260.     if (password.value == "") {
  261.         arrow.style.top = "122px";
  262.         arrow.style.display = "block";
  263.         password.style.background = "indianred";
  264.         password.focus();
  265.         return false;
  266.     }
  267.     
  268.     nickname = nickname.value;
  269.     username = username.value;
  270.     password = password.value;
  271.     address = address.value;
  272.     init_path = init_path.value;
  273.     
  274.     arrow.style.display = "none";
  275.     return true;
  276. }
  277.  
  278. function saveSettings() {
  279.     if (verifySettings()) {    
  280.         if (window.widget) {
  281.             widget.setPreferenceForKey(nickname, widget.identifier + "_nickname");
  282.             
  283.             if (!checkForSavedServer(nickname)) saveServer();
  284.         }
  285.         
  286.         document.getElementById("nickname_display").innerText = nickname;
  287.         populateDropDown();
  288.         
  289.         toggleSettings();
  290.     }
  291. }
  292.  
  293. function toggleSettings() {
  294.     var f = document.getElementById("front");
  295.     var p = document.getElementById("settings");
  296.                
  297.     if (f.style.display != "none") {
  298.         f.style.display = "none";
  299.         p.style.display = "block";
  300.         
  301.         var bod = document.getElementsByTagName("body")[0];
  302.         bod.removeEventListener("mouseover", mouseOver, true);
  303.         bod.removeEventListener("mouseout", mouseOut, true);
  304.         
  305.         document.getElementById("flip").style.display = "none";
  306.           if (!FTPDrop.isRegistered()) document.getElementById("register_buy").style.display = "block";
  307.   
  308.         if (window.widget) widget.prepareForTransition("ToBack");
  309.         
  310.         setTimeout(
  311.             function() {
  312.                 if (nickname == "")
  313.                     document.getElementById("nickname").focus();
  314.                 else
  315.                     document.getElementById("password").focus();
  316.                     
  317.             }, 800);
  318.     } else {
  319.         p.style.display = "none";
  320.         f.style.display = "block";
  321.         
  322.         var bod = document.getElementsByTagName("body")[0];
  323.         bod.addEventListener("mouseover", mouseOver, true);
  324.         bod.addEventListener("mouseout", mouseOut, true);
  325.  
  326.         document.getElementById("flip").style.display = "block";
  327.         
  328.         if (window.widget) widget.prepareForTransition("ToFront");
  329.     }
  330.     if (window.widget) setTimeout("widget.performTransition()", 0);
  331. }
  332.  
  333. //mouseover stuff for the 'i' button:
  334.  
  335. var isShown = false, isAnimating = false;
  336.  
  337. function mouseOver(e) {
  338.     //e.cancelBubble = true;
  339.  
  340.     if (!isShown && !isAnimating) {
  341.     //alert('yo');
  342.     //document.getElementById("flip").style.display = "block";
  343.         fade('flipper', 0, 1, function(){isAnimating=false;isShown = true;});
  344.         isAnimating = true;
  345.     }
  346.     
  347.     if (e.target.parentNode.id == "flip" || e.target.id == "flip") {
  348.         document.getElementById("flip_back").style.visibility = "visible";
  349.     }
  350. }
  351.  
  352. function mouseOut(e) {
  353.     //e.cancelBubble = true;
  354.     
  355.     if (e.target.id != "flipper" && e.target.parentNode.id != "flip") {
  356.         document.getElementById("flip_back").style.visibility = "hidden";
  357.     }
  358.     
  359. //had a lot fo trouble with event capturing, so going this route for now...
  360. //we'll see what happens with actual Tiger...
  361.     if (e.clientY < 0 || e.clientX < 0 || e.clientY > 250 || e.clientX > 230) {
  362.         if (!isAnimating) {
  363.             fade('flipper', 1, 0, function(){isAnimating=false;isShown = false;});
  364.             isAnimating = true;
  365.         }
  366.     }
  367. }
  368.  
  369. function infoMouseUp(e) {
  370.     fade('flipper', 0, 0, function(){isAnimating=false;isShown = false;});
  371.     document.getElementById("flip_back").style.visibility = "hidden";
  372.     toggleSettings();
  373. }
  374.  
  375. function fade(el, from, to, callBack) {
  376.     if (el == new String(el)) el = document.getElementById(el);
  377.     //so we can pass a string for the id or an element
  378.       
  379.     var dif = Math.abs(to - from);
  380.     
  381.     var pi = Math.PI;
  382.     var theta = 0;
  383.     
  384.     //if (to < from && el.style.opacity > 0) return;
  385.     
  386.     var inter = setInterval(
  387.         function() {
  388.             if (theta < 90) {
  389.                 theta += 10;
  390.                 if (to > from) 
  391.                     var step = Math.sin((theta*pi)/180);
  392.                 else 
  393.                     var step = Math.cos((theta*pi)/180);
  394.                 var opac = dif*step;
  395.                 el.style.opacity = Math.max(0.01, opac); //fixing safari glitch
  396.             } else {
  397.                 el.style.opacity = to;
  398.                 clearInterval(inter);
  399.                 if (callBack != null) callBack();
  400.             }
  401.         }, 100);
  402. }
  403.  
  404. function toggleDropDown() {
  405.     var dropdown = document.getElementById("nickname_choices");
  406.     
  407.     if (dropdown.style.display != "block") {
  408.         dropdown.style.display = "block";
  409.     } else {
  410.         dropdown.style.display = "none";
  411.         document.getElementById("nickname_button").src = "images/combo.png";
  412.     }
  413. }
  414.  
  415. function populateDropDown() {
  416.     var dropdown = document.getElementById("nickname_choices");
  417.     
  418.     dropdown.innerHTML = "";
  419.     
  420.     var list = document.createElement("ul");
  421.     
  422.     var data = getSavedServers();
  423.     var servers = data.getElementsByTagName("server");
  424.     
  425.     for (var i=0; i < servers.length; i++) {
  426.         var server = document.createElement("li");
  427.         server.appendChild(document.createTextNode(servers[i].getAttribute("nickname")));
  428.         server.setAttribute("onclick", "getSavedServerInfo('" + servers[i].getAttribute("nickname") + "'); toggleDropDown()");
  429.         list.appendChild(server);
  430.     }
  431.     
  432.     dropdown.appendChild(list);
  433.     
  434.     dropdown.style.height = Math.min(16*servers.length, 100) + "px";
  435.     
  436. }
  437.  
  438. //help stuff:
  439. var help_running = false;
  440.  
  441. function getOffsetTop(element) {
  442.     var top = 0;
  443.     var el = element;
  444.     
  445.     do {
  446.         top += el.offsetTop;
  447.         el = el.parentNode;
  448.     } while (el !== document.body);
  449.     
  450.     return top;
  451. }
  452.  
  453. function getOffsetLeft(element) {
  454.     var left = 0;
  455.     var el = element;
  456.     
  457.     do {
  458.         left += el.offsetLeft;
  459.         el = el.parentNode;
  460.     } while (el !== document.body);
  461.     
  462.     return left;
  463. }
  464.  
  465. var help_canvas_pen, help_canvas_x_stretch, help_canvas_y_stretch;
  466.  
  467. function showHelp() {
  468.     //this is basically an animation showing how to use the widget:
  469.     help_running = true;
  470.  
  471.     //HAHA - the following is almost a joke, isn't it?
  472.     
  473.     document.getElementById("cover").style.display = "block";
  474.     showHelpText(0,
  475.     function () {
  476.         help_canvas_pen = 1;
  477.         help_canvas_y_stretch = 8;
  478.         help_canvas_x_stretch = 10;
  479.         circleObject('settings',
  480.         function () {
  481.             hideHelpText(0, 
  482.             function () {
  483.                 setTimeout(
  484.                 function() {
  485.                     showHelpText(1,
  486.                     function () {
  487.                         help_canvas_pen = 3;
  488.                         help_canvas_y_stretch = 1.5;
  489.                         help_canvas_x_stretch = 8;
  490.                         circleObject('nickname_combo',
  491.                         function () {
  492.                             setTimeout(
  493.                             function() {
  494.                                 hideHelpText(1, 
  495.                                 function () {
  496.                                     setTimeout(
  497.                                     function() {
  498.                                         fade("help_circle_canvas", 1.0, 0, 
  499.                                         function() {
  500.                                             document.getElementById("help_circle_canvas").style.opacity = 1.0;
  501.                                             document.getElementById("help_circle_canvas").style.display = "none";
  502.                                             toggleSettings();
  503.                                             setTimeout(
  504.                                             function() {
  505.                                                 help_canvas_y_stretch = 4;
  506.                                                 help_canvas_x_stretch = 10;
  507.                                                 circleObject('drop_zone',
  508.                                                 function () {
  509.                                                     showHelpText(3,
  510.                                                     function () {
  511.                                                         setTimeout(
  512.                                                         function() {
  513.                                                             hideHelpText(3, 
  514.                                                             function () {
  515.                                                                 showHelpText(4,
  516.                                                                 function () {
  517.                                                                     help_canvas_y_stretch = 3;
  518.                                                                     help_canvas_x_stretch = 7;
  519.                                                                     circleObject('info',
  520.                                                                     function() {
  521.                                                                         setTimeout(
  522.                                                                         function() {
  523.                                                                             hideHelpText(4, 
  524.                                                                             function () {
  525.                                                                                 showHelpText(5,
  526.                                                                                 function () {
  527.                                                                                     setTimeout(
  528.                                                                                     function() {
  529.                                                                                         hideHelpText(5, 
  530.                                                                                         function () {
  531.                                                                                             document.getElementById("help_circle_canvas").style.display = "none";
  532.                                                                                             document.getElementById("cover").style.display = "none";
  533.                                                                                             toggleSettings();
  534.                                                                                         }); //hideHelpText 5
  535.                                                                                     }, 3500);
  536.                                                                                 });//showHelpText 5
  537.                                                                             });//hideHelpText 4
  538.                                                                         }, 3500);
  539.                                                                     });//circleObject 'drop_zone'
  540.                                                                 });//showHelpText 4
  541.                                                             });//hideHelpText 3
  542.                                                         }, 3000);
  543.                                                     });//howHelpText 3
  544.                                                 });//circleObject 'front'
  545.                                             }, 1000);
  546.                                         }); //fade 'help_circle_canvas'
  547.                                     }, 1000);
  548.                                 });//hideHelpText 1
  549.                             }, 3500);
  550.                         });//circleObject 'nickname_combo'
  551.                     });//showHelpText 1
  552.                 }, 3500);
  553.             });//hideHelpText 0
  554.         });//circleObject 'settings'
  555.     });//showHelpText 0
  556. }
  557.  
  558. function cancelHelp() {
  559.     help_running = false;
  560.     document.getElementById("help_circle_canvas").style.display = "none";
  561.     document.getElementById("help_text").style.display = "none";
  562.     document.getElementById("cover").style.display = "none";
  563. }
  564.  
  565. function handleKeyPress(e) {
  566.     if (e.charCode == 27 && help_running) cancelHelp();
  567. }
  568.  
  569. function circleObject(obj, callBack) {
  570.     if (!help_running) return false;
  571.     
  572.     if (obj == new String(obj)) obj = document.getElementById(obj);
  573.     
  574.     var help_context = help_canvas.getContext("2d");
  575.     
  576.     help_canvas.style.display = "block";
  577.     
  578.     help_canvas.style.top = (getOffsetTop(obj) - 35) + "px";
  579.     help_canvas.style.left = (getOffsetLeft(obj) - 35) + "px";
  580.     
  581.     help_context.lineWidth = 1; //help_canvas_pen;
  582.     help_context.lineJoin = "bevel";
  583.     help_context.lineCap = "round";
  584.     help_context.strokeStyle = "rgba(255, 0, 0, 0.8)";
  585.     
  586.     help_context.clearRect(0, 0, 300, 300);
  587.     help_context.save();
  588.     
  589.     help_context.scale(help_canvas_x_stretch, help_canvas_y_stretch);
  590.     
  591.     help_context.beginPath();
  592.     help_context.moveTo(5, 10);
  593.     
  594.     var i=0;
  595.     
  596.     var inter = setInterval(
  597.         function () {
  598.             //alert(i);
  599.             switch (i) {
  600.                 case 0:
  601.                     help_context.bezierCurveTo(5, 0, 20, 10, 20, 20);
  602.                     break;
  603.                 case 1:
  604.                     help_context.beginPath();
  605.                     help_context.moveTo(20, 10);
  606.                     help_context.bezierCurveTo(30, 20, 20, 30, 15, 20);
  607.                     break;
  608.                 case 2:
  609.                     help_context.beginPath();
  610.                     help_context.moveTo(20, 30);
  611.                     help_context.bezierCurveTo(10, 35, 5, 25, 5, 10);
  612.                     break;
  613.                 case 3:
  614.                     help_context.beginPath();
  615.                     help_context.moveTo(5, 25);
  616.                     help_context.bezierCurveTo(2, 7, 9, 10, 0, 0);
  617.                     break;
  618.                 //Default:
  619.                 case 4:
  620.                     clearInterval(inter);
  621.                     help_context.restore();
  622.                     if (callBack != null) callBack();
  623.                     break;
  624.             }
  625.             help_context.stroke();
  626.             i++;
  627.         }, 70);
  628. }
  629.  
  630. function showHelpText(which, callBack) {
  631.     if (!help_running) return false;
  632.     
  633.     var help_text = document.getElementById("help_text");
  634.     help_text.style.display = "block";
  635.     
  636.     var messages = help_text.getElementsByTagName("div");
  637.     if (which > 0) messages[which-1].style.opacity = 0;
  638.     
  639.     fade(messages[which], 0, 0.9, 
  640.         function() {
  641.             //setTimeout("help_text_shadow.paint()", 100);
  642.             callBack();
  643.         });
  644. }
  645.  
  646. function hideHelpText(which, callBack) {
  647.     var help_text = document.getElementById("help_text");
  648.     
  649.     
  650.     var messages = help_text.getElementsByTagName("div");
  651.     //if (which > 0) messages[which-1].style.opacity = 0;
  652.     
  653.     fade(messages[which], 0.9, 0, 
  654.         function () {
  655.             help_text.style.display = "none";
  656.             callBack();
  657.         });
  658. }
  659.  
  660. var help_canvas;
  661.  
  662. function register() {
  663.     if (FTPDrop) FTPDrop.registerWidget();
  664. }
  665.  
  666. function buy() {
  667.     if (FTPDrop) FTPDrop.buyWidget();
  668. }
  669.  
  670. var isNagging = false, flipped = false;
  671.  
  672. function showNag(days_left) {
  673.     //alert('days left (js): ' + days_left);
  674.     isNagging = true;
  675.     document.getElementById("front").style.display = "none";
  676.     document.getElementById("settings").style.display = "none";
  677.     window.resizeTo(341, 134);
  678.     
  679.     //I'll forgo doing this in a nice DOM way for the moment:
  680.     var cont = document.createElement("div");
  681.     cont.id = "buy_panel";
  682.     
  683.     var buy_p_text =  document.createElement("div");
  684.     buy_p_text.id = "buy_panel_text";
  685.     cont.appendChild(buy_p_text);
  686.     
  687.     buy_p_text.innerHTML += '<span id="widget_name">FTP Drop</span> will run without any limitations for ' + days_left + ' more day';
  688.     if (10 - days_left != 1) buy_p_text.innerHTML += 's'
  689.     buy_p_text.innerHTML += '.<br />Thanks for trying it out!\n';
  690.     var buy_p_buts =  document.createElement("div");
  691.     buy_p_buts.id = "buy_buttons";
  692.     cont.appendChild(buy_p_buts);
  693.     
  694.     buy_p_buts.innerHTML += '<a href="#" onclick="FTPDrop.buyWidget()">Buy</a>\n';
  695.     buy_p_buts.innerHTML += '<a href="#" onclick="FTPDrop.registerWidget()">Register</a>\n';
  696.     
  697.     var counter = document.createElement("span");
  698.     counter.id = "counter";
  699.     counter.innerText = 7;
  700.     
  701.     buy_p_buts.appendChild(counter);
  702.     
  703.     document.body.appendChild(cont);
  704.     
  705.     var count_down = 7;
  706.     
  707.     var inter = setInterval(
  708.         function () {
  709.             if (--count_down >= 0) {
  710.                 counter.innerText = count_down;
  711.             } else {
  712.                 clearInterval(inter);
  713.                 window.resizeTo(250, 230);
  714.                 if (!flipped) {
  715.                     document.getElementById("front").style.display = "block";
  716.                     toggleSettings();
  717.                 } else {
  718.                     document.getElementById("settings").style.display = "block";
  719.                     document.getElementById("register_buy").style.display = "block";
  720.                 }
  721.                 
  722.                 document.body.removeChild(cont);
  723.             }
  724.         }, 1000);
  725. }
  726.  
  727. function init() {
  728.     if (window.widget) {
  729.         //alert(widget.identifier);
  730.  
  731.         nickname = widget.preferenceForKey(widget.identifier + "_nickname") || "";
  732.     }
  733.     
  734.     if (nickname != "") {
  735.         if (checkForSavedServer(nickname)) {
  736.             getSavedServerInfo(nickname);
  737.         }
  738.     }
  739.     
  740.     populateDropDown();
  741.     
  742.     //set up the flip ('i') button:
  743.     var bod = document.getElementsByTagName("body")[0];
  744.     bod.addEventListener("mouseover", mouseOver, true);
  745.     bod.addEventListener("mouseout", mouseOut, true);
  746.     document.getElementById("flip").addEventListener("mouseup", infoMouseUp, false);
  747.     
  748.     var drop_zone = document.getElementById("drop_zone");
  749.     drop_zone.addEventListener("drop", getFile, true);
  750.     drop_zone.addEventListener("dragenter", doDragEnter, true);
  751.     drop_zone.addEventListener("dragover", doDragMove, true); 
  752.     drop_zone.addEventListener("dragleave", doDragLeave, true);
  753.     
  754.     setTimeout(
  755.         function () {
  756.             if (!isNagging) {
  757.                 flipped = true;
  758.                 toggleSettings();
  759.             }
  760.         }, 500);
  761.  
  762.     document.addEventListener("keydown", handleKeyPress, false);
  763.     help_canvas = document.getElementById("help_circle_canvas");
  764. }
  765.  
  766. window.onload = init;
  767. if (window.widget) {
  768.     widget.onremove = 
  769.         function() {
  770.             //clear up after ourselves
  771.             widget.setPreferenceForKey(null, widget.identifier + "_nickname");
  772.         };
  773. }